package com.sk.weichat.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.weichat.R;
import com.sk.weichat.bean.DynamicLoactionBean;
import com.sk.weichat.map.MapHelper;
import java.util.List;

/**
 * @Author: chenzl
 * @ClassName: DynamicLocationAdapter
 * @Description: java类作用描述
 * @CreateDate: 2019/10/23 15:46
 */
public class DynamicLocationAdapter extends BaseQuickAdapter<DynamicLoactionBean.LoactionResult, BaseViewHolder> {

    private int position = -1;
    public DynamicLocationAdapter(@Nullable List<DynamicLoactionBean.LoactionResult> data) {
        super(R.layout.layout_dynamic_location, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DynamicLoactionBean.LoactionResult item) {
        helper.setText(R.id.tv_address_title,item.getName());
        TextView tv_address_info = helper.getView(R.id.tv_address_info);
        CheckBox check_select = helper.getView(R.id.check_select);
        if (helper.getAdapterPosition()==0){
            tv_address_info.setVisibility(View.GONE);
        }else {
            tv_address_info.setVisibility(View.VISIBLE);
            tv_address_info.setText(item.getAddress());
        }
        if (helper.getAdapterPosition()==position){
            check_select.setChecked(true);
        }else {
            check_select.setChecked(false);
        }
        check_select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //将点击的位置传出去
                position = helper.getAdapterPosition();
                //刷新界面 notify 通知Data 数据set设置Changed变化
                //在这里运行notifyDataSetChanged 会导致下面的onBindViewHolder 重新加载一遍
                notifyDataSetChanged();
            }
        });
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //将点击的位置传出去
                position = helper.getAdapterPosition();
                //刷新界面 notify 通知Data 数据set设置Changed变化
                //在这里运行notifyDataSetChanged 会导致下面的onBindViewHolder 重新加载一遍
                notifyDataSetChanged();
            }
        });
    }

    public int getPosition() {
        return position;
    }
}
